#include <string.h>
#include "mdk_ep.h"

// set event  
void eventSet(myevent_s *ev, int fd, int (*call_back)(int, int, void*), void *arg)
{  
	memset(ev,0,sizeof(myevent_s));
	ev->fd = fd;  
	ev->call_back = call_back;  
	ev->arg = arg;  
}  
// add/mod an event to epoll  
int eventAdd(int epollFd, int events, myevent_s *ev)
{  
	struct epoll_event epv = {0, {0}};  
	int op;  
	epv.data.ptr = ev;  
	epv.events = ev->events = events;  
#ifdef EP_INTERVAL_DEBUG_FTR
	ev->v_CountAll = 0;
	ev->v_CountFilterd = 0;
#endif
	if(ev->status == 1){  
		op = EPOLL_CTL_MOD;  
	}  
	else{  
		op = EPOLL_CTL_ADD;  
		ev->status = 1;  
	} 
	return epoll_ctl(epollFd, op, ev->fd, &epv);
}  
// delete an event from epoll  
int eventDel(int epollFd, myevent_s *ev)
{  
	struct epoll_event epv = {0, {0}};  
	if(ev->status != 1) return -1;  
	epv.data.ptr = ev;  
	ev->status = 0;  
	return epoll_ctl(epollFd, EPOLL_CTL_DEL, ev->fd, &epv);  
}
